package com.orangelife.mobile.shoppingcart.biz;

import com.curry.android.http.OrangeDataHandler;
import com.curry.android.http.OrangeErrorHandler;
import com.curry.android.http.VolleyHttpUtil;
import com.google.gson.reflect.TypeToken;
import com.orangelife.mobile.confirmOrder.biz.ConfirmOrderHttpBiz;
import com.orangelife.mobile.confirmOrder.biz.GoodsHttpBiz;
import com.orangelife.mobile.shoppingcart.bean.ShoppingCartBean;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

/**
 * 购物车网络请求业务
 * <p/>
 * Created by 绯若虚无 on 2015/10/14.
 */
public class ShoppingCartHttpBiz{

    //TODO 和OrderHttpBiz的getSelectedGoodList是同一个方法，重复
    public static void requestOrderList(List<String> listProductIDs, VolleyHttpUtil.ResponseCallBack callback) {
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("productIDs", map);
//        JSONObject jo = new JSONObject();
//        JSONArray jsonArray = new JSONArray();
//        for (int i = 0; i < listProductIDs.size(); i++) {
//            try {
//                jsonArray.put(i, listProductIDs.get(i));
//            } catch (JSONException e) {
//                e.printStackTrace();
//            }
//        }
//        try {
//            jo.put("productIDs", jsonArray);
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
        HashMap<String,Object> map=new HashMap<>();
        map.put("productIDs",listProductIDs);
        VolleyHttpUtil.getInstance().putWithCallback(GoodsHttpBiz.URL_SELECTED_MERCHANT_GOOD_LIST,map, callback);
    }

    public static List<ShoppingCartBean> handleOrderList(JSONObject response) {
        List<ShoppingCartBean> list = null;
        if (OrangeErrorHandler.getInstance().isSuccess(response)) {
            list = OrangeDataHandler.getListFromJsonWithPageEntity(
                    response, new TypeToken<List<ShoppingCartBean>>() {
                    }.getType(), null, null);
        }
        return list;
    }
}
